package com.cw.subject.domain.handler.subject;

import com.cw.subject.common.enums.IsDeletedFlagEnum;
import com.cw.subject.common.enums.SubjectInfoTypeEnum;
import com.cw.subject.domain.convert.BriefSubjectConverter;
import com.cw.subject.domain.entity.SubjectInfoBO;
import com.cw.subject.domain.entity.SubjectOptionBO;
import com.cw.subject.infra.basic.entity.SubjectBriefPO;
import com.cw.subject.infra.basic.service.SubjectBriefPOService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 简答题目的策略类
 * 
 * @author: 江传文
 * @date: 2024/4/12 16:50
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectBriefPOService subjectBriefPOService;
    
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF; // 只处理BRIEF类型的
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        SubjectBriefPO subjectBriefPO = BriefSubjectConverter.INSTANCE.convertBoToEntity(subjectInfoBO);
        // 其实不进行转化都可,手动赋值就ok
       /* SubjectBriefPO subjectBriefPO = new SubjectBriefPO();
        subjectBriefPO.setSubjectAnswer(subjectInfoBO.getSubjectAnswer());*/

        subjectBriefPO.setSubjectId(subjectInfoBO.getId());
        subjectBriefPO.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        subjectBriefPOService.insert(subjectBriefPO);
    }

    @Override
    public SubjectOptionBO query(int subjectId) {
        SubjectBriefPO subjectBriefPO = new SubjectBriefPO();
        subjectBriefPO.setSubjectId(subjectId);
        SubjectBriefPO result = subjectBriefPOService.queryByCondition(subjectBriefPO);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;
    }

}
